<!--

:mc-config="{'insertUrl':'新增数据接口接收一个主键','redirectUrl':'',paramName:'地址参数名 默认pk',target:''}"
-->
<template>
  <el-button v-bind="$attrs" v-on="$listeners" @click="autoCreate">
    <slot></slot>
  </el-button>
</template>

<script>
export default {
  name: 'mc-pk-creator',
  data () {
    return {
    }
  },
  props:{
    //saveUrl 保存问卷地址 getUrl
    'mcConfig':{type:Object,default:null},
  },
  watch:{

  },
  computed:{

  },
  mounted () {

  },
  updated:function(){

  },
  methods:{
    autoCreate(){
      if(window.iframeUi){
        this.$message("检测到您当前处于设计器界面，跳转会影响设计，您可以在预览页查看跳转")
        return;
      }
      var request = this.$magicaltool.request;
      if(this.mcConfig){
        request.axios({contentType:this.mcConfig.contentType,method:'post',url:this.mcConfig.insertUrl,$vue:this,param:{}}).then(res=>{
          if(res.data){
            if(this.mcConfig.redirectUrl){
              var param = {};
              var key = this.mcConfig.paramName||'pk';
              param[key] = res.data;
              request.util.redirect(this.mcConfig.redirectUrl,this.mcConfig.target,param);
            }
          }
        })
      }
    }
  }
}
</script>

<style lang="scss">

</style>
